﻿using Microsoft.AspNetCore.Mvc;
using SMARTHOTEL.hotel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace SMARTHOTEL.RoomTypes
{
    [ApiExplorerSettings(GroupName = "v1")]
    public class RoomTypeService : ApplicationService, IRoomTypeService
    {

        private readonly IRepository<RoomType> repository;


        public RoomTypeService(IRepository<RoomType> repository)
        {
            this.repository = repository;
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="roomTypeDto"></param>
        /// <returns></returns>
        public async Task<ResultDto<bool>> CreateAllAsync(CreateUpdateRoomTypeDto roomTypeDto)
        {
            try
            {
                RoomType roomType = ObjectMapper.Map<CreateUpdateRoomTypeDto, RoomType>(roomTypeDto);

                await repository.InsertAsync(roomType);

                return new ResultDto<bool> { Data = true,Code= StatusCode.Success, Message = "添加成功" };
            }
            catch (Exception ex)
            {

                return new ResultDto<bool> { Data = false, Code = StatusCode.Faield, Message = "添加失败" };
            }
        }
    }
}
